<template>
  <a-modal width="40%" :label-col="4" :wrapper-col="14" :visible="open" @cancel="onClose" @ok="submitForm">
    <a-divider orientation="left">
      <b>{{ formTitle }}</b>
    </a-divider>
    <a-form-model ref="form" :model="form" :rules="rules">
      <a-form-model-item label="校区" prop="deptId" >
        <a-tree-select
          v-model="form.deptId"
          style="width: 100%"
          :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
          :tree-data="treeData"
          placeholder="请选择校区"
          :replaceFields="{children:'children', title:'label', key:'id', value: 'id' }	"
          tree-default-expand-all
        >
        </a-tree-select>
      </a-form-model-item>
      <a-form-model-item label="一月（单位：元）">
          <a-input v-model="form.yi" placeholder="一月业绩"></a-input>
      </a-form-model-item>
      <a-form-model-item label="二月（单位：元）">
          <a-input v-model="form.er" placeholder="二月业绩"></a-input>
      </a-form-model-item>
      <a-form-model-item label="三月（单位：元）">
          <a-input v-model="form.san" placeholder="三月业绩"></a-input>
      </a-form-model-item>
      <a-form-model-item label="四月（单位：元）">
          <a-input v-model="form.si" placeholder="四月业绩"></a-input>
      </a-form-model-item>
      <a-form-model-item label="五月（单位：元）">
          <a-input v-model="form.wu" placeholder="五月业绩"></a-input>
      </a-form-model-item>
      <a-form-model-item label="六月（单位：元）">
          <a-input v-model="form.liu" placeholder="六月业绩"></a-input>
      </a-form-model-item>
      <a-form-model-item label="七月（单位：元）">
          <a-input v-model="form.qi" placeholder="七月业绩"></a-input>
      </a-form-model-item>
      <a-form-model-item label="八月（单位：元）">
          <a-input v-model="form.ba" placeholder="八月业绩"></a-input>
      </a-form-model-item>
      <a-form-model-item label="九月（单位：元）">
          <a-input v-model="form.jiu" placeholder="九月业绩"></a-input>
      </a-form-model-item>
      <a-form-model-item label="十月（单位：元）">
          <a-input v-model="form.shi" placeholder="十月业绩"></a-input>
      </a-form-model-item>
      <a-form-model-item label="十一月（单位：元）">
          <a-input v-model="form.shiyi" placeholder="十一月业绩"></a-input>
      </a-form-model-item>
      <a-form-model-item label="十二月（单位：元）">
          <a-input v-model="form.shier" placeholder="十二月业绩"></a-input>
      </a-form-model-item>
      <!-- <div class="bottom-control">
        <a-space>
          <a-button type="primary" :loading="submitLoading" @click="submitForm">
            保存
          </a-button>
          <a-button type="dashed" @click="cancel">
            取消
          </a-button>
        </a-space>
      </div> -->
    </a-form-model>
  </a-modal>
</template>

<script>
import { getPerform, addPerform, updatePerform } from '@/api/manager/perform'

export default {
  name: 'CreateForm',
  props: {
    treeData: {
      type: Array,
      required: true
    }
  },
  components: {
  },
  data () {
    return {
      submitLoading: false,
      formTitle: '',
      // 表单参数
      form: {
        id: null,

        deptId: null,

        year: null,

        perform: null,

        month: null,

        createBy: null,

        createTime: null,

        updateBy: null,

        updateTime: null,

        remark: null

      },
      // 1增加,2修改
      formType: 1,
      open: false,
      rules: {
        deptId: [
          { required: true, message: '请选择校区', trigger: 'blur' }
        ],
      }
    }
  },
  filters: {
  },
  created () {
  },
  computed: {
  },
  watch: {
  },
  mounted () {
  },
  methods: {
    onClose () {
      this.open = false
    },
    // 取消按钮
    cancel () {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset () {
      this.formType = 1
      this.form = {
        id: null,

        deptId: null,

        year: null,

        perform: null,

        month: null,

        createBy: null,

        createTime: null,

        updateBy: null,

        updateTime: null,

        remark: null

      }
    },
    /** 新增按钮操作 */
    handleAdd (row) {
      this.reset()
      this.formType = 1
      this.open = true
      this.formTitle = '添加'
    },
    /** 修改按钮操作 */
    handleUpdate (perform) {
      getPerform(perform.deptId,perform.year).then(response => {
        this.form = response.data
        this.open = true
        this.formTitle = '修改'
      })
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.submitLoading = true
          addPerform(this.form).then(response => {
              this.$message.success(
                '编辑成功',
                3
              )
              this.open = false
              this.$emit('ok')
            }).finally(() => {
              this.submitLoading = false
            })
        } else {
          return false
        }
      })
    }
  }
}
</script>
